package example.documentbased.editorModule.common
{
	public class EditorMenuHelper
	{
		public function enable(items:Array, types:Vector.<uint>):void
		{
			if (!(items || types))
				return;
			
			var menuItem:MenuItem;
			
			for (var i:int = 0; i < items.length; i++) 
			{
				menuItem = items[i];
				menuItem.enabled = (types.indexOf(menuItem.type) != -1);
				
				if (menuItem.children && menuItem.children.length)
				{
					enable(menuItem.children, types);
				}
			}
		}
		
		public function createEditorMenu():Array
		{
			var root:MenuItem = new MenuItem(0, "Document");
			
			root.children = [new MenuItem(MenuItemTypes.CREATE, "New"), 
				new MenuItem(MenuItemTypes.OPEN, "Open..."),
				new MenuItem(MenuItemTypes.CLOSE, "Close"),
				new MenuItem(MenuItemTypes.CLOSE_ALL, "Close All"),
				new MenuItem(MenuItemTypes.SAVE, "Save"),
				new MenuItem(MenuItemTypes.SAVE_AS, "Save As..."),
				new MenuItem(MenuItemTypes.SAVE_ALL, "Save All"),
				new MenuItem(MenuItemTypes.DELETE, "Delete")];
			
			return [root];
		}
	}
}